package com.mew.user.service;

import com.mew.common.dc.db.UserService;
import com.mew.common.dc.mapper.GoldDealMapper;
import com.mew.common.dc.redis.UserProfileRedisService;
import com.mew.common.enm.GoldProcessType;
import com.mew.common.enm.UserType;
import com.mew.common.entity.user.Profile;
import com.mew.common.entity.user.User;
import com.mew.common.exception.ResponseCode;
import com.mew.common.rest.gold.TranRecordResponse;
import com.mew.common.util.StringUtils;
import com.mew.user.config.GoldConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
@Slf4j
public class TransferRecordService {


    @Autowired
    private UserService userService;

    @Autowired
    private UserProfileRedisService userProfileRedisService;

    @Autowired
    private GoldDealMapper goldDealMapper;
    @Autowired
    private GoldConfig goldConfig;

    public int customerInfo(long uid, long toUid){

        //自己
        User user = userService.getRedisUserById(uid);

        //未绑手机
        if(StringUtils.isEmpty(user.getTelNumber())){

            return ResponseCode.NoTel.code();
        }
        //低于vip3
        Profile profile = userProfileRedisService.getRedisProfileById(uid);



        if (user.getUserType()== UserType.Common.code() && profile.getVipLevel()<goldConfig.getVip()){
            return ResponseCode.BelowVip.code();
        }

        User byGid = userService.getRedisUserById(toUid);

        if (null==byGid){
            return ResponseCode.UserNotExist.code();
        }


        return ResponseCode.Success.code();
    }


    public TranRecordResponse tranRecord(long uid, int tranType) {
        return TranRecordResponse.builder().tranRecordMessageList(goldDealMapper.getTranRecord(uid,tranType,GoldProcessType.Tran.code())).build();
    }
}
